//
//  GUIController.m
//  Home Saigon
//
//  Created by Aka on 11/28/13.
//  Copyright (c) 2013 Le Zoom. All rights reserved.
//

#import "GUIController.h"

@implementation GUIController
-(id)initWithWindow:(UIWindow*)_window{
    self = [super init];
    window = _window;
    return self;
}
-(void)StartProgram{
    NSLog(@"Program Start");
    firstView = [[FirstViewController alloc]initWithGUI:self];
    [window addSubview:firstView.view];
    //Change View after 1sec
    [self performSelector:@selector(ChangViewToHomeView) withObject:nil afterDelay:3.0];
}
-(void)ChangViewToHomeView{
    homepageView = [[HomePageViewController alloc]initWithGUI:self];
    [window addSubview:homepageView.view];
}
-(void)ShowLoginView{
    NSLog(@"Show Login View");
    if (!isLogin){
        navigation = [[UINavigationController alloc]init];
        loginView = [[LoginViewController alloc]initWithGUI:self];
        [navigation pushViewController:loginView animated:YES];
        [homepageView presentViewController:navigation animated:YES completion:nil];
        NSLog(@"non Login");
    }
    else{
        NSLog(@"yes login");
    }

}

-(void)ScreenFinish:(UIViewController*)sender withCode:(int)code{
    if ((sender==loginView) && (code==1))
    {
        //Check username password for Login
        NSLog(@"Check login");
        [homepageView dismissViewControllerAnimated:YES completion:nil];
        isLogin = YES;
    }
    else if ((sender==loginView) && (code==2))
    {
        //Go to Register Screen
        NSLog(@"Register View");
        registerView = [[RegisterViewController alloc]initWithGUI:self];
        [navigation pushViewController:registerView animated:YES];
    }
    else if ((sender==registerView) && (code==1))
    {
        NSLog(@"Register Button Clicked");
        [navigation popToViewController:loginView animated:YES];
        [loginView setUsername:[registerView getUsername]];
        [loginView setPassword:[registerView getPassword]];
    }
}

@end
